package com.exam.demo.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.demo.common.Result;
import com.exam.demo.entity.Admin;
import com.exam.demo.entity.College;
import com.exam.demo.service.CollegeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 功能描述
 *
 * @author yxj30
 * @date 2022/03/16  19:18
 */
@RestController
@RequestMapping("/college")
public class CollegeController {
    @Resource
    CollegeService collegeService;

    //查找页面数据
    @GetMapping
    public Result findPage(@RequestParam Integer pageNum,
                           @RequestParam Integer pageSize,
                           @RequestParam(defaultValue = "") String collegeName){

        QueryWrapper<College> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("college_name",collegeName);
        Page<College> page = collegeService.page(new Page<>(pageNum, pageSize), queryWrapper);
        return Result.success(page);
    }
    //查找全部学院数据
    @GetMapping("/findAll")
    public Result findPage(){
//        return Result.success(collegeService.findPage(new Page<>(pageNum,pageSize),collegeName));

        List<College> list = collegeService.list();
        return Result.success(list);
    }


    //更改和插入
    @PostMapping("/save")
    public Result insert(@RequestBody College college){
        return Result.success(collegeService.saveOrUpdate(college));
    }

    //删除
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        return Result.success(collegeService.removeById(id));
    }


}
